package ru.housewife.form;

import java.util.*;

/**
 * Abstract form object
 *
 * @author Alexander Troshanin
 */
public abstract class AbstractFormObject<F extends AbstractFormObject> {

    protected <T extends Comparable> List<T> generateSortedCache(Map<Long, T> src) {
        List<T> dst = new ArrayList<T>();
        for (Map.Entry<Long, T> entry : src.entrySet()) {
            dst.add(entry.getValue());
        }
        Collections.sort(dst);
        return dst;
    }

    protected <T extends Comparable> void generateSortedCache(List<T> dst, Map<Long, T> src) {
        dst.clear();
        for (Map.Entry<Long, T> entry : src.entrySet()) {
            dst.add(entry.getValue());
        }
        Collections.sort(dst);
    }

    public abstract void updateFieldsFromSrcForm(F srcForm);
}
